#!/bin/bash

echo "===========arr1=============="
arr1=("zhangsan" "lisi" "wangwu" "zhjaoliu" "tangqi")
echo ${arr1}
echo ${arr1[1]}
echo ${arr1[-1]}
echo ${#arr1[@]}        #获取数组的长度
echo ${arr1[*]}         #获取数组中所有的元素

echo "===========遍历arr1==========="
for (( i = 0; i < ${#arr1[@]}; ++i )); do
    echo ${arr1[i]}
done


echo "===========arr2==============="
arr2=([0]="zhangsan" [1]="lisi" [2]="wangwu" [3]="zhaoliu" [4]="tangqi")
echo ${arr2}
echo ${arr2[1]}

echo "===========遍历arr2============"
for item in ${arr2[*]} ; do
    echo ${item}
done


echo "===========arr3==============="
arr3[0]="zhangsan"
arr3[1]="lisi"
arr3[2]="wangwu"
arr3[3]="zhaoliu"
arr4[4]="tangqi"
echo ${arr3}
echo ${arr3[1]}

echo "===========arr4==============="
arr4=(`ls /e/server`)
echo ${arr4}
echo ${arr4[1]}

echo "===========arr5==============="
declare -A arr5
arr5["name"]="zhansan"
arr5["age"]=23
arr5["phone"]="18115188243"
arr5["hobby"]="lanqiu"
echo ${arr5["age"]}
echo ${arr5["phone"]}
echo ${arr5[*]}

#数组总结
#   1、arr数组是以空格隔开，不是以逗号隔开
#   2、打印数组变量默认取数组第一个值
#   3、数组下标取值
#       正向索引从左往右，默认从0开始计数
#       负向索引从右往左，默认从-1开始计数
#   4、声明关联数组：declare -A